package com.cskaoyan.jdbc;

import com.cskaoyan.jdbc.util.JdbcUtil;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @ClassName CUDJdbc
 * @Description: TODO
 * @Author 远志 zhangsong@cskaoyan.onaliyun.com
 * @Date 2023/2/6 17:14
 * @Version V1.0
 **/
public class CUDJdbc {

    public static void main(String[] args) {
        Connection connection = null;
        Statement statement = null;
        try {
            connection = JdbcUtil.getConnection();
            statement = connection.createStatement();
            //执行该条sql语句影响的行数
            //插入时中文乱码，如何排查？
            //首先先排查数据库本身是否有问题，使用命令去自行插入中文数据，看是否乱码
//            int i = statement.executeUpdate("insert into customer values (null, '张益达','武汉')");
//            int i = statement.executeUpdate("update customer set name = '张大炮' where id = 7");
            int i = statement.executeUpdate("delete from customer where id = 6");

            System.out.println(i);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                JdbcUtil.release(connection, statement, null);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }
}
